@import '../../styles/variables.less';
@import '../../styles/themes/@{so-theme}.less';

@tree-prefix: ~'@{so-prefix}-tree';
@tree-line-value: 2px;
@tree-transparent-value: 3px;
@tree-rtl: ~'@{so-prefix}-rtl';

.@{tree-prefix} {
  position: relative;

  &-node {
    position: relative;
    padding-left: @tree-indicator-size;
    line-height: @line-height-base;

    > .@{tree-prefix}-children {
      margin-left: @tree-level-indent;
    }

    & > div {
      padding-bottom: @tree-node-margin-bottom;
    }

    &:last-child > div {
      padding-bottom: 0;
    }
  }

  &-with-line {
    > .@{tree-prefix}-node:only-child:before {
      display: none;
    }
    .@{tree-prefix}-node {
      &:before {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 6px;
        width: 1px;
        background: linear-gradient(to bottom, @tree-line-color, @tree-line-color @tree-line-value, transparent @tree-transparent-value, transparent);
        background-size: 100% @tree-line-value * @tree-transparent-value;
        content: ' ';
      }

      &:after {
        position: absolute;
        top: 11px;
        left: 7px;
        width: 14px;
        height: 1px;
        background: linear-gradient(to right, @tree-line-color, @tree-line-color @tree-line-value, transparent @tree-transparent-value, transparent);
        background-size: @tree-line-value * @tree-transparent-value 100%;
        content: ' ';
      }

      &:last-child:before {
        top: -4px;
        bottom: auto;
        height: 14px;
      }

      &:first-child:before {
        top: -4px;
      }
    }

    &.@{tree-prefix} > .@{tree-prefix}-node:first-child:before {
      top: 9px;
    }

    .@{tree-prefix}-icon-plus,
    .@{tree-prefix}-icon-sub {
      position: absolute;
      z-index: 10;
      top: 3px;
      left: 0px;

      &:hover span.@{tree-prefix}-default-icon {
        border-color: @colors-primary;
      }

      &:focus span.@{tree-prefix}-default-icon {
        .input-focus()
      }

      span.@{tree-prefix}-default-icon {
        position: relative;
        display: inline-block;
        width: 13px;
        height: 13px;
        border: solid 1px @tree-indicator-color;
        background: #fff;
        border-radius: 2px;

        &:before {
          position: absolute;
          top: 5px;
          left: 2px;
          display: block;
          width: 7px;
          height: 0;
          border-bottom: solid 1px transparent;
          border-color: inherit;
          content: ' ';
        }
      }
    }

    .@{tree-prefix}-icon-plus span.@{tree-prefix}-default-icon {
      &:after {
        position: absolute;
        top: 2px;
        left: 5px;
        display: block;
        width: 0;
        height: 7px;
        border-right: solid 1px transparent;
        border-color: inherit;
        content: ' ';
      }
    }
  }

  &-no-line {
    .@{tree-prefix}-icon-plus,
    .@{tree-prefix}-icon-sub {
      position: absolute;
      z-index: 10;
      top: 0px;
      left: 0px;
      width: 16px;

      &:after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        display: inline-block;
        padding: 12px;
        transition: all .2s;
        z-index: -1;
      }

      &:hover {
        &::after {
          background: @gray-100;
        }
      }

      .@{tree-prefix}-default-icon {
        border-left-color: @gray-600;
      }

      span.@{tree-prefix}-default-icon {
        position: absolute;
        top: 8px;
        left: 10px;
        display: inline-block;
        width: 0;
        height: 0;
        border-width: 4px 5px;
        border-style: solid;
        border-color: transparent transparent transparent @tree-indicator-color;
        transform-origin: 2px 4px;
        transition: transform 0.2s linear;
      }
    }

    .@{tree-prefix}-icon-sub span.@{tree-prefix}-default-icon {
      transform: rotate(90deg);
    }
  }

  &-icon-loading {
    position: absolute;
    z-index: 10;
    top: 3px;
    left: 0px;
    width: 12px;
    height: 12px;
    background: #fff;
  }

  &-content {
    z-index: 10;
    display: flex;
    line-height: 24px;

    .@{tree-prefix}-text {
      flex: 1;
    }
  }

  &-checkbox {
    z-index: 10;
    margin-right: 6px;
    font-size: 0;
  }

  &-drag-place {
    position: relative;
    z-index: 0;
    width: 100%;
    height: 0;

    div {
      border: dashed 1px #ddd;
      background: @gray-100;
    }
  }


  &.@{tree-prefix}-rtl {
    direction: rtl;
    text-align: right;
    .@{tree-prefix}-node {
      padding-left: 0;
      padding-right: @tree-indicator-size;


      .@{tree-prefix}-icon-plus,
      .@{tree-prefix}-icon-sub {
        left: auto;
        right: 0;

        .@{tree-prefix}-default-icon {
          transform: rotate(180deg);
        }
      }

      .@{tree-prefix}-icon-sub {
        .@{tree-prefix}-default-icon {
          transform: rotate(90deg);
        }
      }
    }


    &.@{tree-prefix}-with-line {
      .@{tree-prefix}-node {
        &:before {
          left: auto;
          right: 5px;
        }
        &:after {
          left: auto;
          right: 6px;
        }
      }
    }
  }
}
